/**
 * 
 */
package co.fitstart.mobile.dao.support;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.entity.credit.product.CreditProduct;
import co.fitstart.entity.credit.product.CreditProductTag;

/**
 * @author Guangli Yan
 *
 */
@Repository("creditProductDaoSupport")
public class CreditProductDaoSupport {

	@Autowired
	private GenericDaoSupport genericDaoSupport;
	
	/**
	 * @param tag
	 * @param beginIndex
	 * @param maxResultRecords
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CreditProduct> list(CreditProductTag tag, int beginIndex, int maxResultRecords) {
		
		String sentence = "FROM CreditProduct WHERE disabled = false AND tags LIKE :tag ";
		
		Map<String, Object> parameters = new HashMap<>();
		
		parameters.put("tag", "%"+tag.getAlias()+"%");
		
		List<CreditProduct> result = genericDaoSupport.searchForList(sentence, parameters, beginIndex, maxResultRecords);
		
		return result;
	}

}
